package net.maku.propagate.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import net.maku.framework.common.utils.PageResult;
import net.maku.framework.common.utils.Result;
import net.maku.propagate.convert.PropagateNewsConvert;
import net.maku.propagate.entity.PropagateNewsEntity;
import net.maku.propagate.service.PropagateNewsService;
import net.maku.propagate.query.PropagateNewsQuery;
import net.maku.propagate.vo.PropagateNewsVO;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;
import java.util.List;

/**
* 新闻资讯
*
* @author 阿沐 babamu@126.com
* @since 1.0.0 2025-03-16
*/
@RestController
@RequestMapping("propagate/news")
@Tag(name="新闻资讯")
@AllArgsConstructor
public class PropagateNewsController {
    private final PropagateNewsService propagateNewsService;

    @GetMapping("page")
    @Operation(summary = "分页")
    public Result<PageResult<PropagateNewsVO>> page(@ParameterObject @Valid PropagateNewsQuery query){
        PageResult<PropagateNewsVO> page = propagateNewsService.page(query);

        return Result.ok(page);
    }

    @GetMapping("{id}")
    @Operation(summary = "信息")
    public Result<PropagateNewsVO> get(@PathVariable("id") Long id){
        PropagateNewsEntity entity = propagateNewsService.getById(id);

        return Result.ok(PropagateNewsConvert.INSTANCE.convert(entity));
    }

}